﻿using Lis.IBLL;
using Lis.Model;
using Lis.WebApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Lis.WebApp.Controllers
{
    [XfhExceptionHandler]
    public class UserInfoController : ApiController
    {
        public IUserInfoService UserInfoService { get; set; }

        public ICirculateService CirculateService { get; set; }

        public IAppointmentService AppointmentService { get; set; }

        #region 01，获取用户信息+ServiceResult<object> ReaderCarNo(string value)
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<object> ReaderCarNo(string value)
        {
            try
            {
                return UserInfoService.GetById(value);
            }
            catch (Exception)
            {
                return new ServiceResult<object>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion

        #region 02，当前借阅+ServiceResult<IEnumerable<object>> LoanBook(string value)
        /// <summary>
        /// 当前借阅
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<IEnumerable<object>> LoanBook(string value)
        {
            try
            {
                return CirculateService.GetEntitiesOfLoanByUserName(value);
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion

        #region 03，借阅历史+ServiceResult<IEnumerable<object>> LoanHistoryBook(string value)
        /// <summary>
        /// 借阅历史
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<IEnumerable<object>> LoanHistoryBook(string value)
        {
            try
            {
                return CirculateService.GetEntitiesOfLoanHistoryByUserName(value);
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion

        #region 04，获取预约记录+ServiceResult<IEnumerable<object>> HoldBook(string value)
        /// <summary>
        /// 获取预约记录
        /// </summary>
        /// <param name="value">读者卡号</param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<IEnumerable<object>> HoldBook(string value)
        {
            try
            {
                return AppointmentService.GetEntitiesByUserName(value);
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion
    }
}
